package com.example.demo.controller;
import com.example.demo.request.QueryRequest;
import com.example.demo.service.QueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
// import org.springframework.web.bind.annotation.CrossOrigin;

//@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/api/ollama")
public class QueryController {

    @Autowired
    private QueryService queryService;

    @PostMapping("/chat")
    public ResponseEntity<String> getResponse(@RequestBody QueryRequest request) {
        try {
            // Assuming 'stream' defaults to false in your service layer
            System.out.println("Request: " + request.getQuery());
            String response = queryService.sendQuery(request);
            return ResponseEntity.ok(response);

        } catch (Exception e) {
            return ResponseEntity.status(500).body("Error: " + e.getMessage());
        }
    }
}
